package com.ktgj.flight.common.qunar;

import com.ktgj.flight.domain.InterfaceEntity.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @author wyj
 * @create 2021-09-27 10:12
 */
public class TestQunar {


    public static void main(String[] args){
         Logger logger = LoggerFactory.getLogger(TestQunar.class);
        _Qunar qunar = new _Qunar();

                     //机票查询
        MoFlightSearchRequest request = new MoFlightSearchRequest();
        //出发城市代码 一个
        request.GoSearchWhere.OrgAirport="PEK";
        //到达城市代码 一个
        request.GoSearchWhere.DstAirport="SHA";
        //查询出发日期 一个
        request.GoSearchWhere.DepDate="2022-03-25";
        //行程类型
        request.TripType=1;

        //回程日期
        //request.BackSearchWhere.DepDate="2022-03-12";





        MoFlightSearchResponse moFlightSearchResponse = qunar._FlightSearch(request);
        System.out.println(moFlightSearchResponse.toString());

        /*for (MoFlightInfo moFlightInfo : moFlightSearchResponse.ListGoFlightInfo) {

            logger.info("航班号：{} --》抵达机场代码：{} --》抵达机场名称：{} --》抵达机场航站楼:{} --》出发机场代码: {} --》 出发机场名称：{} --》 出发机场航站楼：{}",
                    moFlightInfo.FlightNo, moFlightInfo.DstAirport, moFlightInfo.DstAirportName, moFlightInfo.ArrTerm, moFlightInfo.OrgAirport, moFlightInfo.OrgAirportName, moFlightInfo.DepTerm);

            String format = String.format("航班号: %s ======= 抵达机场代码: %s ===== 抵达机场名称：%s ====== 抵达机场航站楼: %s ===== 出发机场代码: %s ===== 出发机场名称：%s ==== 出发机场航站楼：%s",
                    moFlightInfo.FlightNo,moFlightInfo.DstAirport,moFlightInfo.DstAirportName,moFlightInfo.ArrTerm,moFlightInfo.OrgAirport,moFlightInfo.OrgAirportName,moFlightInfo.DepTerm);

            System.out.println(format);
        }*/




        //航班报价
        //单程
        /*QnnarFlightSearchPriceResponse qnnarFlightSearchPriceResponse = qunar._FlightSearchPrice( "PEK", "SHA", "2021-12-12", "CZ8883", "");*/

        //往返
       /* QnnarFlightSearchPriceResponse qnnarFlightSearchPriceResponse = qunar._FlightSearchPrice("PEK", "SHA",
                "2021-12-12", "KN5737_KN5738", "2021-12-19");*/



                    //查询退改签
        //单程
        /*MoCabinTgqRequest moRequest = new MoCabinTgqRequest();
        moRequest.FlightNo = "CA1605";
        moRequest.DepDate = "2022-03-02";
        moRequest.Cabin = "Y";
        moRequest.OrgAirport = "PEK";
        moRequest.DstAirport = "DLC";
        moRequest.PolicyId = "2959";
        moRequest.Price = new BigDecimal(1230);
        moRequest.OnlyCode = "20191101130135296314";
       // moRequest.RequestType = 16;
        moRequest.BuyerCode = "100";
        moRequest.ProviderCode = null;
        moRequest.BackDate = null;
        moRequest.TripType = 0;
        moRequest.Carrier = "";
        moRequest.IsCodeShare = false;
        moRequest.ProductType = null;
        moRequest.CabinType = "0";*/


       //往返
        /*MoCabinTgqRequest moRequest = new MoCabinTgqRequest();
        moRequest.FlightNo = "CA1605_CA8903";
        moRequest.DepDate = "2022-03-02";
        moRequest.Cabin = "Y_Y";
        moRequest.OrgAirport = "PEK";
        moRequest.DstAirport = "DLC";
        moRequest.PolicyId = "2959";
        moRequest.Price = new BigDecimal(2460);
        moRequest.OnlyCode = "20191101130135296314";
        moRequest.BuyerCode = "100";
        moRequest.ProviderCode = null;
        moRequest.BackDate = null;
        moRequest.TripType = 0;
        moRequest.Carrier = "";
        moRequest.IsCodeShare = false;
        moRequest.ProductType = null;
        moRequest.CabinType = "0";
        moRequest.BackDate = "2022-03-05";

        qunar._GetCabinTgq(moRequest);*/




                    //验价
//        MoFlightCheckRequest moRequest = new MoFlightCheckRequest();
//        moRequest.FlightNo = "KN5737";
//        moRequest.DepDate = "2021-10-10";
//        moRequest.Cabin = "D";
//        moRequest.OrgAirport = "PEK";
//        moRequest.DstAirport = "SHA";
//        moRequest.Airline = "FM";
//        moRequest.PolicyID = "0";
//        moRequest.ProductType = "0";
//        moRequest.Price = new BigDecimal(618);
//        moRequest.TripType = "1";
//
//        QunarFlightCheckResponse qunarFlightCheckResponse = qunar._FlightCheck(moRequest);


                    //单程
        //创建订单之前验价数据临时
        /*MoFlightCheckRequest moFlightCheckRequest = new MoFlightCheckRequest();
        moFlightCheckRequest.FlightNo = "CA1605";
        moFlightCheckRequest.DepDate = "2022-03-01";
        moFlightCheckRequest.Cabin = "Y";
        moFlightCheckRequest.OrgAirport = "PEK";
        moFlightCheckRequest.DstAirport = "DLC";
        moFlightCheckRequest.Airline = "CA";
        moFlightCheckRequest.PolicyID = "0";
        moFlightCheckRequest.ProductType = "0";
        moFlightCheckRequest.Price = new BigDecimal(1230);
        moFlightCheckRequest.TripType = "1";

        QunarFlightCheckResponse qunarFlightCheckResponse = qunar.Test_FlightCheck(moFlightCheckRequest);*/


        //创建订单
        MoCreateOrderRequest moRequest = new MoCreateOrderRequest();
        moRequest.PolicyID = "2";
        MoSegment moSegment = new MoSegment();
        moSegment.FlightNo= "CA1605";
        moSegment.OrgAirport = "PEK";
        moSegment.DstAirport = "DLC";
        moSegment.DepDate=convertToDate("2022-03-01 09:45:00","yyyy-MM-dd HH:mm:ss");
        moSegment.ArrDate=convertToDate("2022-03-01 11:20:00","yyyy-MM-dd HH:mm:ss");
        moSegment.Cabin="Y";

        moRequest.ListGoSegment.add(moSegment);


        MoPassenger moPassenger = new MoPassenger();
        moPassenger.PassengerName ="王亚杰";
        moPassenger.PassengerType =1;
        moPassenger.IDType=1;
        moPassenger.IDNO="620521199710260030";
        moPassenger.Sex=false;
        moPassenger.PassengerMobile="17610641000";
        moPassenger.Birthday=convertToDate("1997-10-26","yyyy-MM-dd");

        moRequest.ListMoPassenger.add(moPassenger);

        MoContacts contacts= new MoContacts();
        contacts.ContactName="王亚杰";
        contacts.ContactPreNum="86";
        contacts.ContactMobile="15037102578";
        contacts.Address="北京";

        moRequest.Contacts =contacts;

        moRequest.IsNeedPost = true;

        moRequest.TripType = 1;

                //往返
       /* MoFlightCheckRequest moFlightCheckRequest = new MoFlightCheckRequest();
        moFlightCheckRequest.FlightNo = "KN5737_KN5738";
        moFlightCheckRequest.DepDate = "2021-10-30";
        moFlightCheckRequest.Cabin = "D_D";
        moFlightCheckRequest.OrgAirport = "PEK";
        moFlightCheckRequest.DstAirport = "SHA";
        moFlightCheckRequest.Airline = "FM";
        moFlightCheckRequest.PolicyID = "0";
        moFlightCheckRequest.ProductType = "0";
        moFlightCheckRequest.Price = new BigDecimal(1240);
        moFlightCheckRequest.TripType = "2";
        moFlightCheckRequest.BackDate="2021-11-10";

        QunarFlightCheckResponse qunarFlightCheckResponse = qunar.Test_FlightCheck(moFlightCheckRequest);


        //创建订单
        MoCreateOrderRequest moRequest = new MoCreateOrderRequest();
        moRequest.PolicyID = "2";
            //去
        MoSegment moSegment = new MoSegment();
        moSegment.FlightNo= "KN5737";
        moSegment.OrgAirport = "PEK";
        moSegment.DstAirport = "SHA";
        moSegment.DepDate=convertToDate("2021-11-15 07:10:00","yyyy-MM-dd HH:mm:ss");
        moSegment.ArrDate=convertToDate("2021-11-15 09:20:00","yyyy-MM-dd HH:mm:ss");
        moSegment.Cabin="D";
            //往返
        MoSegment back = new MoSegment();
        moSegment.FlightNo= "KN5738";
        moSegment.OrgAirport = "SHA";
        moSegment.DstAirport = "PEK";
        moSegment.DepDate=convertToDate("2021-11-22 10:35:00","yyyy-MM-dd HH:mm:ss");
        moSegment.ArrDate=convertToDate("2021-11-22 13:00:00","yyyy-MM-dd HH:mm:ss");
        moSegment.Cabin="D";

        moRequest.ListGoSegment.add(moSegment);
        moRequest.ListBackSegment.add(back);


        MoPassenger moPassenger = new MoPassenger();
        moPassenger.PassengerName ="王亚杰";
        moPassenger.PassengerType =1;
        moPassenger.IDType=1;
        moPassenger.IDNO="620521199710260030";
        moPassenger.PassengerMobile="17610641000";
        moPassenger.Sex=false;
        moPassenger.Birthday=convertToDate("1997-10-26","yyyy-MM-dd");

        moRequest.ListMoPassenger.add(moPassenger);

        MoContacts contacts= new MoContacts();
        contacts.ContactName="王亚杰";
        contacts.ContactPreNum="86";
        contacts.ContactMobile="15037102578";
        contacts.Address="北京";

        moRequest.Contacts =contacts;

        moRequest.IsNeedPost = true;

        moRequest.TripType = 2;
*/
        //调用方法
        MoCreateOrderResponse moCreateOrderResponse = qunar._OrderCreate(moRequest);



        //查询订单
        /*MoQueryOrderRequest orderRequest = new MoQueryOrderRequest();
        orderRequest.OrderID = "xep211011144603162"; //往返订单
        //orderRequest.OrderID ="ghc211012120327817";
        //调用方法
        qunar._QueryOrderInfo(orderRequest);*/



        //订单验价
        /*MoOrderCheckRequest request = new MoOrderCheckRequest();
        request.OrderID ="xgx211012103030442";
        qunar._OrderCheck(request);*/


        //支付订单
        /*MoOrderPayRequest request = new MoOrderPayRequest();
        request.MainOutOrderID = "ghc211012120327817";
        qunar._OrderPay(request);*/



        //申请改签
       /* MoOrderChangeRequest changeRequest = new MoOrderChangeRequest();
        changeRequest.IsFree = false;
        changeRequest.OrderId="ghc211012120327817";

        ChangeAirOriDest oriDest = new ChangeAirOriDest();
        oriDest.DepApt= "PEK";
        oriDest.FlightNo = "CA1605";
        oriDest.ArrApt="DLC";
        oriDest.Cabin="Y";

        changeRequest.NewChangeAirOriDest=oriDest;

        qunar._OrderChange(changeRequest);*/


        //申请退票
        /*MoOrderRefundRequest refundRequest = new MoOrderRefundRequest();
        refundRequest.OrderID = "ghc211012120327817";
        refundRequest.RefundType = 1; //退票类型为自愿

        MoPassenger moPassenger = new MoPassenger();
        moPassenger.PassengerName="王亚杰";

        refundRequest.ListMoPassenger.add(moPassenger);

        qunar._OrderRefund(refundRequest);*/



        //上传附件

        /*MoAttachmentRequest request = new MoAttachmentRequest();
        request.OrderId = "ghc211012120327817";
        request.OtherParams ="21851536";*/


        //String strNo = "ghc211012120327817";
        /*qunar.bx(strNo);*/



    }

    public static Date convertToDate(String str,String pattern){
        SimpleDateFormat sdf=new SimpleDateFormat(pattern);
        Date date=null;
        if(str!=null){
            try {
                date=sdf.parse(str);
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
        return date;
    }

}
